import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login'
import Home from '../views/Home'
import User from '../views/system/User'
import Role from "../views/system/Role";
import Menu from "../views/system/Menu";
import Log from "../views/system/Log";
import Allcar from "../views/rents/Allcar";
import CarType from "../views/rents/CarType";
import CarConfig from "../views/rents/CarConfig";
import CarBrand from "../views/rents/CarBrand";
import CarShop from "../views/rents/CarShop";
import CarComment from "../views/rents/CarComment";
import Position from "../views/marketing/Position";
import CustomerIssues from "../views/marketing/CustomerIssues";
import Advertise from "../views/marketing/Advertise";

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: "/Login"
    },
    {
        path: '/login',
        name: 'Login',
        component: Login
    },

    {
                path: "/home",
                name: "home",
                component: Home,
                children: [
                    {
                        path: "/",
                        name: "main",
                        component: () => import('../views/system/main'),
                    },
                    {
                        path: "/system/user",
                        name: "user",
                        component: User,
                    },
                    {
                        path: "/system/role",
                        name: "role",
                        component: Role,
                    },
                    {
                        path: "/system/log",
                        name: "log",
                        component: Log,
                    },
                    {
                        path: "/system/menu",
                        name: "menu",
                        component: Menu,
                    },
                    {
                        path: "/rents/allcar",
                        name: "Allcar",
                        component: Allcar,
                    },
                    {
                        path: "/rents/carType",
                        name: "carType",
                        component: CarType,
                    },
                    {
                        path: "/rents/carConfig",
                        name: "carConfig",
                        component: CarConfig,
                    },
                    {
                        path: "/rents/carBrand",
                        name: "carConfig",
                        component: CarBrand,
                    },
                    {
                        path: "/rents/carShop",
                        name: "carShop",
                        component: CarShop,
                    },
                    {
                        path: "/rents/carComment",
                        name: "carComment",
                        component: CarComment,
                    },
                    {
                        path: "/client/coupon",
                        name: "Coupon",
                        component: () => import("../views/client/Coupon.vue"),
                    },
                    {
                        path: "/client/couponRecord",
                        name: "CouponRecord",
                        component: () => import("../views/client/CouponRecord.vue"),
                    },
                    {
                        path: "/client/integral",
                        name: "Integeal",
                        component: () => import("../views/client/Integral.vue"),
                    },
                    {
                        path: "/client/vip",
                        name: "Vip",
                        component: () => import("../views/client/Vip.vue"),
                    },
                    {
                        path: "/client/vipLevel",
                        name: "VipLevel",
                        component: () => import("../views/client/VipLevel.vue"),
                    }, {
                        path: "/marketing/position",
                        name: "position",
                        component: Position
                    },
                    {
                        path: "/marketing/advertise",
                        name: "advertise",
                        component: Advertise
                    },
                    {
                        path: "/marketing/customerissues",
                        name: "customerissues",
                        component: CustomerIssues
                    },
                    {
                        path: "/maintain/record",
                        name: "record",
                        component: () => import('../views/maintain/Record')
                    },
                    {
                        path: "/maintain/shop",
                        name: "shop",
                        component: () => import('../views/maintain/Shop')
                    },
                    {
                        path: "/statistics/order",
                        name: "order",
                        component: () => import('../views/statistics/Order')
                    },
                    {
                        path: "/statistics/Echarts2",
                        name: "Echarts2",
                        component: () => import('../views/statistics/Echarts2')
                    },
                ]
            }

        ]

        const router = new VueRouter({
            routes
        })
//to去向 from:从哪走 next：放行
        router.beforeEach((to, from, next) => {
            var path = to.path;
            if (path === '/login') {
                return next();
            }
            var token = sessionStorage.getItem("token");
            if (token) {
                return next();
            }
            next("/login");
        })
        export default router
